
package org.springblade.modules.videoanswer.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.videoanswer.entity.Group;
import org.springblade.modules.videoanswer.vo.GroupVO;
import org.springblade.modules.videoanswer.service.IGroupService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.Date;
import java.util.List;

/**
 * 群组管理 控制器
 *
 * @author jiangyandong
 * @since 2021-03-22
 */
@RestController
@AllArgsConstructor
@RequestMapping("/videoanswer/group")
@Api(value = "群组管理", tags = "群组管理接口")
public class GroupController extends BladeController {

	private IGroupService groupService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入group")
	public R<Group> detail(Group group) {
		Group detail = groupService.getOne(Condition.getQueryWrapper(group));
		return R.data(detail);
	}

	/**
	 * 分页 群组管理
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入group")
	public R<IPage<Group>> list(Group group, Query query) {
		IPage<Group> pages = groupService.page(Condition.getPage(query), Condition.getQueryWrapper(group));
		return R.data(pages);
	}

	/**
	 * 自定义分页 群组管理
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入group")
	public R<IPage<GroupVO>> page(GroupVO group, Query query) {
		IPage<GroupVO> pages = groupService.selectGroupPage(Condition.getPage(query), group);
		return R.data(pages);
	}

	/**
	 * 新增 群组管理
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入group")
	public R save(@Valid @RequestBody Group group) {
		return R.status(groupService.save(group));
	}

	/**
	 * 修改 群组管理
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入group")
	public R update(@Valid @RequestBody Group group) {
		return R.status(groupService.updateById(group));
	}

	/**
	 * 新增或修改 群组管理
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入group")
	public R submit(@Valid @RequestBody Group group) {
		BladeUser loginUser = SecureUtil.getUser();
		if(group.getId() == null){
			group.setCreateUser(loginUser.getUserId());
		}
		group.setUpdateTime(new Date());
		group.setUpdateUser(loginUser.getUserId());
		return R.status(groupService.saveOrUpdate(group));
	}


	/**
	 * 删除 群组管理
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(groupService.removeByIds(Func.toIntList(ids)));
	}

	/**
	 * 分页 群组管理
	 */
	@PostMapping("/noPagelist")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "无分页", notes = "传入group")
	public R<List<Group>> noPagelist(@Valid @RequestBody List<Group> groups) {
		List<Group> groupList = groupService.noPagelist(groups);
		return R.data(groupList);
	}
}
